#include <iostream>
#include <filesystem>
#include <vector>
#include <regex>
using namespace std;

namespace fs = filesystem;

const string pwd = "20020918";
vector<fs::directory_entry> fileList;

vector<fs::directory_entry> getAllFiles(string path) {
	vector<fs::directory_entry> fileList;
	regex regSelf(".*\\.(cpp|exe)");
	
	fs::path str("./");
	if (!fs::exists(str)) {
		cout << "Path doesn't exists!" << endl;
		throw "Path doesn't exists!";
	}
	
	fs::directory_entry entry(str);
	if (entry.status().type() != fs::file_type::directory) {
		cout << "This is not a directory!" << endl;
		throw "This is not a directory!";
	}
	fs::directory_iterator list(str);
	
	for (auto item: list) {
		string fileString = item.path().filename().string();
		if (regex_match(fileString, regSelf))
			continue;
		fileList.emplace_back(item);
	}
	
	return fileList;
}

void encode(vector<fs::directory_entry>& fileList) {
	for (auto& item: fileList) {
		fs::path from(item.path());
		fs::path to(item.path().stem().string() + ".ini");
		fs::rename(from, to);
	}
}

void decode(vector<fs::directory_entry>& fileList) {
	for (auto& item: fileList) {
		fs::path from(item.path());
		fs::path to(item.path().stem().string() + ".mp4");
		fs::rename(from, to);
	}
}

void display() {
	string cmd;
	while (true) {
		cin >> cmd;
		if (cmd == "exit")
			return;
		else if(cmd == "help") {
			cout << "1. encode \n2.[password]\n";
		}
		else if(cmd == pwd) {
			decode(fileList);
			return ;
		}
		else if(cmd == "encode") {
			encode(fileList);
			return ;
		}
	}
}


int main() {
	
	try {
		fileList = getAllFiles("./");
	}catch (const string msg) {
		cout << msg << endl;
		return -1;
	}
	
	display();
	
	
	
	return 0;
}
